package com.youuvs.feignClient;

import com.youuvs.JsonResult;
import com.youuvs.domain.Product;
import com.youuvs.domain.Store;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/store")
@FeignClient(name="store-server",fallbackFactory = StoreFeignFallbackFactory.class)
public interface StoreFeignClient {
    @RequestMapping("/getById/{id}")
    Store getById(@PathVariable("id") Long id);

    @PostMapping("/sto/insert")
    JsonResult insert(@RequestBody Store store);

}


class StoreFeignFallbackFactory implements FallbackFactory<StoreFeignClient>{

    @Override
    public StoreFeignClient create(Throwable throwable) {
        return new StoreFeignClient() {
            @Override
            public Store getById(Long id) {
                return new Store(-1L,-1L,-1);
            }

            @Override
            public JsonResult insert(Store store) {
                return new JsonResult().setMsg("熔断触发");

            }
        };
    }
}